package com.xuxin.baby.model;

import com.xuxin.baby.base.BaseConstant;
import com.xuxin.baby.bean.BaseBean;
import com.xuxin.baby.bean.ReaderVideoBean;
import com.xuxin.baby.contract.ReaderVideoContract;
import com.xuxin.baby.network.Retrofit;
import com.xuxin.baby.network.RetrofitApi;
import com.xuxin.baby.network.myObserver;
import com.xuxin.baby.presenter.ReaderVideoPresenter;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.observers.DisposableObserver;
import io.reactivex.rxjava3.schedulers.Schedulers;

/**
 * Created by xu_xin
 * Created on 2020/10/23 0023
 * 视频文章
 */
public class ReaderVideoModel implements ReaderVideoContract.Model {

    @Override
    public void getReaderVideo(ReaderVideoPresenter presenter,
                               String tenantId,
                               String token,
                               String categoryId,
                               String keywords,
                               String isRec,
                               String type,
                               String ageRge,
                               int skipCount) {
        Retrofit.getInstance().createReq(RetrofitApi.class)
                .getReaderVideo(tenantId,
                        token,
                        "1",
                        categoryId,
                        keywords,
                        isRec,
                        type,
                        ageRge,
                        skipCount * BaseConstant.page_limit,
                        BaseConstant.page_limit)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new myObserver<ReaderVideoBean>() {
                    @Override
                    public void onNextX(@NonNull ReaderVideoBean readerVideoBean) {
                        if (readerVideoBean.isSuccess()) {
                            presenter.onSuccess(readerVideoBean);
                        } else {
                            presenter.onError(readerVideoBean);
                        }
                    }
                    @Override
                    public void onError(BaseBean baseBean) {
                        presenter.onError(baseBean);
                    }
                    @Override
                    public void onError(@NonNull Throwable e) {
                        presenter.onError(null);
                    }

                    @Override
                    public void onComplete() {
                        presenter.onComplete();
                    }
                });
    }
}